package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.entity.Question_fpa;
import com.aaa.service.Question_fpaService;
import com.aaa.util.Enum01;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;


@Controller
@RequestMapping("question")
public class QuestionController extends BaseController{

    @Autowired
    private Question_fpaService question_fpaService;

    MyReturn myReturn=new MyReturn();

    @RequestMapping("toShowQuestionPage.do")
    public String toShowUserPage(){
        return "showQuestion";
    }

    /**
    * @Author: WTH
    * @Description: 查询，分页,计算总条数
    * @Date:2022-06-29 14:52
    * @Params:
    */
    @ResponseBody
    @RequestMapping("selectQuestion.do")
    public MyReturn selectQusetion(Question_fpa question){
        Page quesPage = question_fpaService.selectQuestion_fpa(question);
        myReturn.setData(quesPage.getResult());
        myReturn.setCount(quesPage.getTotal());
        super.getSuccessReturn(myReturn);
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 新增
    * @Date:2022-06-29 17:04
    * @Params:
    */
    @ResponseBody
    @RequestMapping("addQuestion.do")
    public MyReturn addQuestion(Question_fpa question){
        question.setCreate_time(new Date());
        question.getCreate_by();
        Enum01 enum01 = question_fpaService.insertQuestion(question);
        myReturn.setCode(enum01.getCode());
        myReturn.setMsg(enum01.getMsg());
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 修改
    * @Date:2022-06-29 20:09
    * @Params:
    */
    @ResponseBody
    @RequestMapping("updateQuestion.do")
    public MyReturn updateQuestion(Question_fpa question){
        question.setUpdate_time(new Date());
        int i = question_fpaService.updateQuestion(question);
        if(i>0){
            return super.getSuccessReturn(myReturn);
        }else{
            return super.getFailReturn(myReturn);
        }
    }

    /**
    * @Author: WTH
    * @Description: 删除
    * @Date:2022-06-29 20:34
    * @Params:
    */
    @ResponseBody
    @RequestMapping("deleteQuestion.do")
    public MyReturn deleteQuestion(String id){
        boolean b = question_fpaService.deleteQuestion(id);
        if(b){
            return super.getSuccessReturn(myReturn);
        }
        return super.getFailReturn(myReturn);
    }




    /**
     * 查询所有，储存题库
     */

    @RequestMapping("questionAllfpa.do")
    public String question_fpa(HttpSession session){
        List<Question_fpa> question_fpas=question_fpaService.questionAllfpa();
        session.setAttribute("questionf",question_fpas);
        return "fpaTest";
    }

}
